vim.api.nvim_command("set foldmethod=expr")
vim.api.nvim_command("set foldexpr=nvim_treesitter#foldexpr()")

require("nvim-treesitter.configs").setup({
	-- One of 'all', 'maintained' (pasets with maintainers), or
	-- a list of languages
	ensure_installed = "all",

	-- Install languages synchronously (only applied to
	-- `ensure_installed`)
	sync_install = false,

	-- List of parsers to ignore installing
	-- ignore_install = {
	-- 	'javascript'
	-- },

	highlight = {
		-- `false will disable the whole extension
		enable = true,

		-- List of language that will be disabled
		-- disable = { 'c', 'rust' },

		-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
		-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
		-- Using this option may slow down your editor, and you may see some duplicate highlights.
		-- Instead of true it can also be a list of languages
		additional_vim_regex_highlighting = false,
	},
	-- no @class.outer/inner for lua
	textobjects = {
		select = {
			enable = true,

			-- Automatically jump forward to textobj, similar to targets.vim
			lookahead = true,

			keymaps = {
				-- Can use the capture groups defined in textobjects.scm
				["af"] = "@function.outer",
				["if"] = "@function.inner",
				["ac"] = "@class.outer",
				["ic"] = "@class.inner",
			},
		},
		swap = {
			enable = true,

			swap_next = {
				["<leadr>a"] = "@parameter.inner",
			},
			swap_previous = {
				["<leader>A"] = "@parameter.inner",
			},
		},
		move = {
			enable = true,
			set_jumps = true, -- whether to set jumps in the jumplist
			goto_next_start = {
				["]["] = "@function.outer",
				["]c"] = "@class.outer",
			},
			goto_next_end = {
				["]]"] = "@function.outer",
				["]C"] = "@class.outer",
			},
			goto_previous_start = {
				["[["] = "@function.outer",
				["[c"] = "@class.outer",
			},
			goto_previous_end = {
				["[]"] = "@function.outer",
				["[C"] = "@class.outer",
			},
		},
		lsp_interop = {
			enable = true,
			border = "none",
			peek_definition_code = {
				["<leader>df"] = "@function.outer",
				["<leader>dF"] = "@class.outer",
			},
		},
	},
	rainbow = {
		enable = true,
		-- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for
		extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
		max_file_lines = 1000, -- Do not enable for files with more than n lines, int
		-- colors = {}, -- table of hex strings
		-- termcolors = {} -- table of colour name strings
	},
	context_commentstring = {
		enable = true,
	},
})
